// pages/xiaoxi/paihang/index.js
const myRequest = require("../../../utils/require.js")
const Time =require("../../../utils/util.js")
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:'',
    all_rank:0,
    dian_rank:0,
    qu_rank:0,
    ranking:[],
    user_total:0,
    month:12,
    year:0,
    time:'',
    end_time:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.CheckSession().then(res => {
      if (res == true) {
        app.GetUser().then(data => {
          this.initTime()
          this.apiRequest()
          this.setData({
            userInfo: data
          })
        })
      };
    });

  },
  apiRequest(){
    myRequest.myRequest('User/rank', { time: this.data.time }, 'GET').then(success => {
      this.setData({
        all_rank: success.data.all_rank[0].oid,
        dian_rank: success.data.dian_rank[0].oid,
        qu_rank: success.data.qu_rank[0].oid,
        ranking: success.data.ranking,
        user_total: success.data.user_total,
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
      
  },
  initTime(){
   let time= Time.dateFormat("Y-m",new Date())
   console.log(time)
    let array = time.split("-")

    this.setData({
      month: array[1].replace(/\b(0+)/gi, ""),
      year: array[0],
      time: time,
      end_time:time
    })
  },
  getDateTime(e){
    console.log(e)
    let time=e.detail.value
    let array=time.split("-")
   
    this.setData({
      month: array[1].replace(/\b(0+)/gi, ""),
      year:array[0],
      time:time
    })
    this.apiRequest()

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  loadpage: function () {
    // 显示加载图标
    this.setData({
      show: true
    })
    let status = this.data.status
    let page = this.data.page
    let workshops = this.data.workshop
    wx.request({
      url: 'http://127.0.0.1:8000/agentApi/' + "month_ranking",
      method: "GET",
      success: res => {
        this.setData({
          all_rank: res.data.all_rank[0].oid,
          dian_rank: res.data.dian_rank[0].oid,
          qu_rank: res.data.qu_rank[0].oid,
          ranking: res.data.ranking,
        })
        
      }
    })
  }
})